﻿
using AutoMapper;
using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.EndingOnly
{
    public class ProductionScratchesCreateHandler : IRequestHandler<ProductionScratchesCreateCommond, Resqults>
    {
        private readonly IBateRepository<ProductionScratches> _ProductionScratches;
        private readonly IMapper mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productionScratches"></param>
        /// <param name="mapper"></param>
        public ProductionScratchesCreateHandler(IBateRepository<ProductionScratches> productionScratches, IMapper mapper)
        {
            _ProductionScratches = productionScratches;
            this.mapper = mapper;
        }
        /// <summary>
        /// 化膘新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Resqults> Handle(ProductionScratchesCreateCommond request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults res = new Resqults() { Code = 0 };
                ProductionScratches info = mapper.Map<ProductionScratches>(request);
                res.Code = await _ProductionScratches.Add(info);
                if (res.Code > 0)
                {
                    res.Messges = "成功";
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
